﻿Public Class Edit_delivery
    Private Sub Edit_delivery_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Namesender.Text = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Имя рассылки")
        CheckBox1.Checked = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ДТ отправлена")
        CheckBox2.Checked = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Присвоен номер")
        CheckBox3.Checked = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Начата проверка")
        CheckBox4.Checked = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Доп.проверка по стране")
        CheckBox9.Checked = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Увед. о досмотре")
        CheckBox5.Checked = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Доп.проверка по стоимости")
        CheckBox6.Checked = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Акт досмотра")
        CheckBox7.Checked = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Проверка окончена")
        CheckBox8.Checked = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Выпуск товаров")
        If Len(My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:Имя")) > 0 Then mark1.Text = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:Имя")
        If Len(My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:там.пост")) > 0 Then mark2.Text = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:там.пост")
        If Len(My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:коммент")) > 0 Then mark3.Text = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:коммент")
        If Len(My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:ком+xls")) > 0 Then mark4.Text = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:ком+xls")
        Emails.Text = My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Emails")
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Try
            Process.Start(Application.StartupPath & "\Template\")
        Catch
            MsgBox("странно, но папка не найдена" & vbNewLine & Application.StartupPath & "\Template\")
        End Try
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Me.Close()
        address.Show()
        address.TopMost = True
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ' есть резервные поля в этой таблице
        My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Имя рассылки") = Namesender.Text
        My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ДТ отправлена") = CheckBox1.Checked
        My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Присвоен номер") = CheckBox2.Checked
        My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Начата проверка") = CheckBox3.Checked
        My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Доп.проверка по стране") = CheckBox4.Checked
        My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Увед. о досмотре") = CheckBox9.Checked
        My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Доп.проверка по стоимости") = CheckBox5.Checked
        My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Акт досмотра") = CheckBox6.Checked
        My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Проверка окончена") = CheckBox7.Checked
        My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Выпуск товаров") = CheckBox8.Checked
        If Mid(mark1.Text, 1, 1) <> "{" Then My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:Имя") = mark1.Text
        If Mid(mark2.Text, 1, 1) <> "{" Then My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:там.пост") = mark2.Text
        If Mid(mark3.Text, 1, 1) <> "{" Then My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:коммент") = mark3.Text
        If Mid(mark4.Text, 1, 1) <> "{" Then My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("ИД:ком+xls") = mark4.Text
        My.Settings.Set_address.Rows(Convert.ToInt32(rowindex.Text)).Item("Emails") = Emails.Text
        My.Settings.Save()
        Me.Close()
        address.Show()
        address.TopMost = True
    End Sub

    Private Sub Emails_TextChanged(sender As Object, e As EventArgs) Handles Emails.LostFocus
        Emails.Text = Replace(Emails.Text, vbNewLine, ", ") 'меняем новую строку на запяту
        Emails.Text = Replace(Emails.Text, ", , ", ", ") 'удаляем лишие запятые
        Emails.Text = Replace(Emails.Text, ",,", ",") 'удаляем лишие запятые
        Emails.Text = Trim(Replace(Emails.Text, "  ", " ")) 'удаляем лишние пробелы
        If Len(Emails.Text) > 0 Then If Mid(Emails.Text, Len(Emails.Text), 1) = "," Then Emails.Text = Mid(Emails.Text, 1, Len(Emails.Text))
    End Sub
End Class